home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 45
/
Aminet 45 (2001)(GTI - Schatztruhe)[!][Oct 2001].iso
/
Aminet
/
game
/
role
/
ldmud-3.2-bin.lha
/
mud
/
doc
/
efun
/
sprintf
< prev
next >
Wrap
Text File
|
2001-07-18
|
6KB
|
110 lines
SYNOPSIS
string sprintf(string fmt, ...)
DESCRIPTION
Most of the characters in the format string <fmt> get passed
straight through to the output (ie: printed or put in the
return string), to format the arguments into the string it's
necessary to include an argument format string (AFS) in the
FMT. An AFS is a series of characters starting with a percent
sign "%" and terminated with a argument type specifier.
To include a "%" sign in the output, it is necessary to include a
double percent sign "%%". The sequence "%^" will output "%^" again.
Valid argument type specifiers are:
"s" : the argument is a string.
"d" : the argument is an integer to be included in decimal
representation.
"i" : same as "d".
"o" : the argument is an integer to be included in octal
representation.
"x" : the argument is an integer to be included in hexidecimal
representation.
"X" : as "x" except letters are capitalised.
e,E,f,F,g,G like in c.
"O" : the argument is an LPC datatype to be printed in an arbituary
format, this is for debugging purposes.
If the argument is an object then the function printf_obj_name() on
the master object is called with the object as a parameter, the string
returned is included in brackets at the end of object file name.
If 0 is returned then nothing is appended after the file name.
Between the percent sign and the argument type specifier in
the AFS, the following modifiers can be included to specify
the formatting information. Order is not important unless
otherwise specified. "n" is used to specify a integer, which
can be a "*" in which case the next argument is used as the
number.
Modifiers:
n specifys the field size. If the size is prepended with
a 0, the argument is printed with leading zeroes.
"."n specifies the presision, for simple (not columns or tables)
strings specifies the truncation length.
":"n n specifies the fs _and_ the presision, if n is prepended by a zero
then the pad string is set to "0".
"'X'" the pad string is set to the char(s) between the single quotes,
if the field size is also prepended with a zero then which ever
is specified last will overrule.
NOTE: to include "'" in the pad string, you must use "\\'"
(as the backslash has to be escaped past the interpreter),
similarly, to include "\" requires "\\\\".
" " pad positive integers with a space.
"+" pad positive integers with a plus sign.
"-" left adjusted within field size.
NB: std (s)printf() defaults to right justification, which is
unnatural in the context of a mainly string based language
but has been retained for "compatability" ;)
"|" centered within field size.
"=" column mode. Ignored unless the argument type specifier is s.
Field size must be specified, if precision is specified then it
specifies the width for the string to be wordwrapped in, if not
then the field size is. The field size specifies the width of
the column and has the effect that the last line of the column
is padded with spaces to achieve this length.
"#" table mode. Ignored unless the argument type specifier is s.
Field size must be specified, if presision is specified then it
specifys the number of columns in the table, otherwise the
number is "optimally" generated. Table mode is passed a list
of slash-n separated 'words' which are put in a format similar
to that of ls.
"@" the argument is an array. the corresponding AFS (minus all
"@") is applied to each element of the array.
When the formatting of an element results in several output lines
(column or table mode) and no explicite pad strings has been
defined, then the efun removes any padding whitespace before
the newlines of all but the last line. However, if an explicite
pad string has been given, even if it is the simple ' ', then
the padding will not be removed.
EXAMPLES
sprintf("decimal=%d, octal=%o, hexadecimal=%x\n", 7, 7, 7);
sprintf("array=%O\n", ({1, 2, 3}));
this will return the following:
({ /* sizeof() == 3 */
1,
2,
3
})
An array will be printed recursively and each element of the
array will be indented. Can also be used as a debugging tool.
sprintf("%-*#s\n", 80, implode(get_dir("~/."), "\n"));
Produces a table with the filenames from directory ~/. .
sprintf("%-=3s", "fo bar") --> "fo\nbar"
sprintf("%-=' '3s", "fo bar") --> "fo \nbar"
HISTORY
LDMud 3.2.9 added the "%^" sequence for compatibility with
terminal_colour(), clarified the meaning of leading
0s in the field size modifier, and clarified the interaction
between the padding and newlines.
SEE ALSO
printf(E), terminal_colour(E)